package com.selftool.service;

import com.selftool.mapper.ModelMapper;
import com.selftool.mapper.PatchMapper;
import com.selftool.util.CommonUtil;
import com.selftool.vo.ModelVO;
import com.selftool.vo.PatchVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: selftool
 * @description: jdbc服务实现
 * @author: CYQ
 * @create: 2024-02-29 17:16
 **/

@Service
public class JDBCServerImpl implements JDBCService{
    @Autowired
    ModelMapper modelServer;
    @Autowired
    PatchMapper patchServer;
    /**
     * @param tablename
     * @return
     */
    @Override
    public String[][] getModel(String[] title,String tablename) {
        List<ModelVO> model = modelServer.selectList(null);
        List<PatchVO> patch = patchServer.selectList(null);
//        //创建二维数组，存储数据
//        Object[][] data = {
//                {"SIP合并补丁", "问题修复01", "2023-08-14 17:50:20", ""},
//                {"SIP合并补丁", "问题修复02", "2023-08-14 17:50:21", ""},
//                {"SIP合并补丁", "问题修复03", "2023-08-14 17:50:22", ""}};
        String[][] data = new String[patch.size()][title.length];
        //循环处数据，补全列
        for(int n=0;n<patch.size();n++){
            PatchVO vo = patch.get(n);
            //循环处理数据，补全行
            for(int i=0;i<title.length;i++){
                String name = title[i];
                String code = model.stream().filter(m -> name.equals(m.getName())).findAny().orElse(null).getCode();
                data[n][i] = CommonUtil.initstr(vo.getAttributeValue(code));
            }
        }

        return data;
    }
}
